package com.itcast.user.service.impl;

import com.itcast.common.UserOrderDTO;
import com.itcast.user.dao.UserMapper;
import com.itcast.user.feign.OrderFeign;
import com.itcast.user.pojo.User;
import com.itcast.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private OrderFeign orderFeign;

    @Override
    public List<UserOrderDTO> findList(String username) {
        User user = userMapper.selectByPrimaryKey(username);
        List<UserOrderDTO> userOrderDTOS = orderFeign.getOrders(username);

        for (UserOrderDTO userOrderDTO : userOrderDTOS) {
          //将user有关信息 复制到userOrderDTO里
            BeanUtils.copyProperties(user,userOrderDTO);
        }

        return userOrderDTOS;
    }
}
